﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace MusicOnSpace
{
    public class dataProvider
    {
        SqlConnection con;
        SqlDataAdapter da;
        DataSet ds;
        SqlCommand cmd;

        public void connect()
        {
            if (con == null)
                con = new SqlConnection("server=.; database=bcdonlinesv; integrated security = true;");
            if (con.State == ConnectionState.Closed)
                con.Open();
        }

        public void disconnect()
        {
            if ((con != null) && (con.State == ConnectionState.Open))
                con.Close();
        }

        public DataSet get(string sql)
        {
            connect();
            da = new SqlDataAdapter(sql, con);
            ds = new DataSet();
            da.Fill(ds);
            disconnect();
            return ds;
        }

        public void ExeCuteNonQuery(string sql)
        {
            connect();
            cmd = new SqlCommand(sql, con);
            cmd.ExecuteNonQuery();
            disconnect();
        }

        public void getSearch(string name)
        {
            connect();
            string command = "Select * from Songs where songName= 'N" + name + "'";
            ExeCuteNonQuery(command);
        }
    }
}